﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RAMED
{
    public partial class CarteForm2 : Form
    {
        public Bordereau_Form_Modif_lot modifeirborderaeuForm = new Bordereau_Form_Modif_lot();
        public Carte Carte
        {
            get;
            set;
        }

        
        public Carte carteajoute { get; set; }


        public CarteForm2()
        {
            InitializeComponent();
            
            RAMEDEntities1 Context = SingletonContext.GetContext();
            comboBoxcentresante2.DataSource = Context.Centre_sante;
            comboBoxcentresante2.DisplayMember = "nom_centre_sante";
            comboBoxcentresante2.ValueMember = "id_centre_sante";
        }

        internal void InitialiserChamps()
        {
            txtnom2.Text = Carte.Nom_benefi;
            txtprenom2.Text = Carte.Prenom_benefi;
            txtipcm2.Text = Carte.IPCM.ToString();
            txtcin2.Text = Carte.CIN_benefi;

            comboBoxcentresante2.SelectedValue = Carte.id_centre_sante;
        }

        private void AjouterCarteModifierBordereau2_Load(object sender, EventArgs e)
        {
            
  

            
            
        }

        private void btnajoutercarte2_Click(object sender, EventArgs e)
        {
            if (ValidateChildren(ValidationConstraints.Enabled))
            {

                RAMEDEntities1 Context = SingletonContext.GetContext();
                carteajoute = new Carte();
                carteajoute.CIN_benefi = txtcin2.Text;
                carteajoute.Prenom_benefi = txtprenom2.Text;
                carteajoute.Nom_benefi = txtnom2.Text;
                carteajoute.IPCM = txtipcm2.Text;
                carteajoute.Centre_sante = ((Centre_sante)comboBoxcentresante2.SelectedItem);
                modifeirborderaeuForm.Cartebordereau2.Add(carteajoute);
                modifeirborderaeuForm.mettreAjourFormGridView();
                Context.SaveChanges();

                this.Dispose();
            }
        }

        private void txtnom2_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs Nom est obligatoire", txtnom2, e, errorProvider1);
        }

        private void label6_Click(object sender, EventArgs e)
        {
            
        }

        private void txtprenom2_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs Prénom est obligatoire", txtprenom2, e, errorProvider1);
        }

        private void txtcin2_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs CIN est obligatoire", txtcin2, e, errorProvider1);
        }

        private void txtipcm2_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("saisez un nombre valide", txtipcm2, e, errorProvider1);
        }
    }
}
